var e = require;
var t = module;
var o = exports;
Object.defineProperty(o, "__esModule", {value: !0});
var n = e("NotifyEventType"),
    a = e("GlobalParams"),
    i = e("AssetsManager"),
    r = e("ModuleUI"),
    s = e("CommonHelper"),
    l = e("EquipInfo"),
    c = e("equip_item_info"),
    d = e("sdkConfig"),
    h = e("AD"),
    _ = e("Toast"),
    u = e("BuyEquipInfo"),
    p = cc._decorator,
    m = p.ccclass,
    f = p.property,
    g = (function (e) {
        function t() {
            var t = (null !== e && e.apply(this, arguments)) || this;
            return (
                (t.equip_item = null),
                (t.equip_view = null),
                (t.btn_view = null),
                (t.nom_equip_view = null),
                (t.equip_name_label = null),
                (t.equip_icon_sprite = null),
                (t.int_info_node = null),
                (t.equip_skill_list = []),
                (t.use_equip_view = null),
                (t.buy_btn = null),
                (t.sell_btn = null),
                (t.have_coin_num_label = null),
                (t.equip_type = ["nom", "att", "hp", "speed", "cool"]),
                (t.choose_equip_info = null),
                (t.sell_index = 0),
                t
            );
        }
        return (
            __extends(t, e),
            (t.prototype.initView = function () {
                e.prototype.initView.call(this);
                for (var t = 0; t < 3; t++) {
                    for (var o = 0; o < 4; o++)
                        (a = cc.instantiate(this.equip_item)).setParent(this.equip_view.children[t]);
                    for (o = 0; o < 5; o++) {
                        var a;
                        (a = cc.instantiate(this.equip_item)).setPosition(cc.v2(0, -40 - 85 * o)),
                            a.setParent(this.nom_equip_view.children[t]);
                    }
                }
                this.attachEvent(n.default.SEND_CHOOSE_EQUIP_INFO, this.showChooseEquipInfo, this),
                    this.showBtnViewInfo("nom"),
                    this.showUseEquip(),
                    this.showHaveCoin();
            }),
            (t.prototype.addEvent = function () {
                this.attachEvent(n.default.SEND_UPDATE_MATCH_PLAYER_INFO, this.showHaveCoin, this);
            }),
            (t.prototype.showHaveCoin = function () {
                this.have_coin_num_label.string = "" + a.GlobalParams.MatchGamePlayer[a.GlobalParams.MatchMyIndex].coin;
            }),
            (t.prototype.OnClick = function (t) {
                var o = this;
                e.prototype.OnClick.call(this, t);
                var i = t.node.name;
                switch (i) {
                    case "back_btn":
                        d.default.platform == d.EPlatform.TikTok && h.default.getInstance().ResumeRecorder(),
                            this.node.destroy();
                        break;
                    case "nominate_equip_btn":
                        this.showBtnViewInfo("nom");
                        break;
                    case "equip_att_btn":
                        this.showBtnViewInfo("att");
                        break;
                    case "equip_hp_btn":
                        this.showBtnViewInfo("hp");
                        break;
                    case "equip_speed_btn":
                        this.showBtnViewInfo("speed");
                        break;
                    case "equip_cooling_btn":
                        this.showBtnViewInfo("cool");
                        break;
                    case "equip_0":
                    case "equip_1":
                    case "equip_2":
                    case "equip_3":
                    case "equip_4":
                        var r = s.default.getNameType(i, "equip_");
                        this.sell_index = r;
                        var c = a.GlobalParams.MatchGamePlayer[a.GlobalParams.MatchMyIndex].equip_info;
                        if (c[r] > 0) {
                            for (var p = 0; p < this.use_equip_view.childrenCount; p++)
                                this.use_equip_view.children[p].getChildByName("choose").active = p == r;
                            var m = l.default.eqquip_info[c[r]];
                            this.emitEvent(n.default.SEND_CHOOSE_EQUIP_INFO, {use: !0, info: m});
                        }
                        break;
                    case "buy_btn":
                        var f = this.choose_equip_info.eq_sale,
                            g = a.GlobalParams.MatchGamePlayer[a.GlobalParams.MatchMyIndex].equip_info,
                            v = [];
                        for (p = 0; p < this.choose_equip_info.eq_need.length; p++)
                            -1 != g.indexOf(this.choose_equip_info.eq_need[p]) &&
                                ((f -= l.default.eqquip_info[this.choose_equip_info.eq_need[p]].eq_sale),
                                v.push(g.indexOf(this.choose_equip_info.eq_need[p])));
                        if (a.GlobalParams.MatchGamePlayer[a.GlobalParams.MatchMyIndex].coin >= f) {
                            for (p = 0; p < v.length; p++) g[v[p]] = 0;
                            for (
                                g[g.indexOf(0)] = this.choose_equip_info.eq_ID,
                                    a.GlobalParams.MatchGamePlayer[a.GlobalParams.MatchMyIndex].coin -= f,
                                    a.GlobalParams.MatchGamePlayer[a.GlobalParams.MatchMyIndex].equip_info = g,
                                    this.showUseEquip(),
                                    u.default.playerBuyEquipInfo(a.GlobalParams.MatchMyIndex, function () {
                                        o.emitEvent(
                                            n.default.SEND_UPDATE_BUY_EQUIP_NEW_ADD_INFO,
                                            a.GlobalParams.MatchMyIndex
                                        );
                                    }),
                                    p = 0;
                                p < this.choose_equip_info.eq_need.length;
                                p++
                            ) {
                                var y = a.GlobalParams.MyNomEquipInfo.indexOf(this.choose_equip_info.eq_need[p]);
                                -1 != y && a.GlobalParams.MyNomEquipInfo.splice(y, 1);
                            }
                            a.GlobalParams.MyNomEquipInfo.splice(
                                a.GlobalParams.MyNomEquipInfo.indexOf(this.choose_equip_info.eq_ID),
                                1
                            ),
                                this.emitEvent(n.default.SEND_UPDATE_MATCH_PLAYER_INFO);
                        } else _.default.showNewToast("金币不足");
                        break;
                    case "sell_btn":
                        (a.GlobalParams.MatchGamePlayer[a.GlobalParams.MatchMyIndex].coin +=
                            0.5 * this.choose_equip_info.eq_sale),
                            (a.GlobalParams.MatchGamePlayer[a.GlobalParams.MatchMyIndex].equip_info[
                                this.sell_index
                            ] = 0),
                            this.showUseEquip(),
                            this.emitEvent(n.default.SEND_UPDATE_MATCH_PLAYER_INFO),
                            u.default.playerBuyEquipInfo(a.GlobalParams.MatchMyIndex, function () {
                                o.emitEvent(n.default.SEND_UPDATE_BUY_EQUIP_NEW_ADD_INFO, a.GlobalParams.MatchMyIndex);
                            });
                }
            }),
            (t.prototype.showBtnViewInfo = function (e) {
                for (var t = 0; t < 5; t++)
                    (this.btn_view.children[t].children[0].active = e != this.equip_type[t]),
                        (this.btn_view.children[t].children[1].active = e == this.equip_type[t]);
                "nom" != e ? this.showEquipViewInfo(e) : this.showNomEquipInfo(),
                    (this.equip_view.active = "nom" != e),
                    (this.nom_equip_view.active = "nom" == e);
            }),
            (t.prototype.showEquipViewInfo = function (e) {
                var t = [];
                "att" == e
                    ? (t = l.default.equip_att_info)
                    : "hp" == e
                    ? (t = l.default.equip_hp_info)
                    : "speed" == e
                    ? (t = l.default.equip_speed_info)
                    : "cool" == e && (t = l.default.equip_cooling_info);
                for (var o = 0; o < 3; o++)
                    for (var a = 0; a < 4; a++) this.equip_view.children[o].children[a].active = !1;
                for (o = 0; o < t.length; o++) {
                    var i = l.default.eqquip_info[t[o]],
                        r = this.equip_view.children[i.eq_level - 1].children[i.eq_index];
                    r.getComponent(c.default).showEquipInfo(i), (r.active = !0);
                }
                this.emitEvent(n.default.SEND_CHOOSE_EQUIP_INFO, {use: !1, info: l.default.eqquip_info[t[0]]});
            }),
            (t.prototype.showNomEquipInfo = function () {
                for (
                    var e =
                            l.default.equip_nominate_info[
                                a.GlobalParams.MatchGamePlayer[a.GlobalParams.MatchMyIndex].role_id
                            ].nom_equip,
                        t = null,
                        o = 0;
                    o < e.length;
                    o++
                ) {
                    var i;
                    i = l.default.eqquip_info[e[o]];
                    for (var r = 0; r < i.eq_need.length; r++) {
                        var s = l.default.eqquip_info[i.eq_need[r]];
                        this.addNomEquipItem(s, o), null == t && (t = s);
                    }
                    this.addNomEquipItem(i, o);
                }
                this.emitEvent(n.default.SEND_CHOOSE_EQUIP_INFO, {use: !1, info: t});
            }),
            (t.prototype.addNomEquipItem = function (e, t) {
                var o = this.nom_equip_view.children[e.eq_level - 1].children[t];
                o.getComponent(c.default).showEquipInfo(e), (o.active = !0);
            }),
            (t.prototype.showChooseEquipInfo = function (e, t) {
                this.choose_equip_info = t.info;
                var o = t.info;
                (this.equip_name_label.string = "" + o.eq_name),
                    (this.equip_icon_sprite.spriteFrame = i.default
                        .getInstance()
                        .getEquipIconFrame("equip_" + o.eq_ID));
                for (var n = 0; n < this.equip_skill_list.length; n++)
                    (this.equip_skill_list[n].active = o.eq_skill[n]),
                        this.equip_skill_list[n].active &&
                            ((this.equip_skill_list[n].getChildByName("type").getComponent(cc.Label).string =
                                o.eq_skill[n]),
                            (this.equip_skill_list[n].getChildByName("info").getComponent(cc.Label).string =
                                o.eq_skill_des[n]));
                for (n = 0; n < 2; n++)
                    (this.int_info_node.children[n].active = o.eq_int[n]),
                        this.int_info_node.children[n] &&
                            (this.int_info_node.children[n].children[0].getComponent(cc.Label).string = o.eq_int[n]);
                if (((this.buy_btn.interactable = !t.use), (this.sell_btn.interactable = t.use), !t.use))
                    for (n = 0; n < this.use_equip_view.childrenCount; n++)
                        this.use_equip_view.children[n].getChildByName("choose").active = !1;
            }),
            (t.prototype.showUseEquip = function () {
                for (
                    var e = a.GlobalParams.MatchGamePlayer[a.GlobalParams.MatchMyIndex].equip_info, t = 0;
                    t < this.use_equip_view.childrenCount;
                    t++
                ) {
                    var o = this.use_equip_view.children[t];
                    (o.getChildByName("equip").getComponent(cc.Sprite).spriteFrame =
                        0 == e[t] ? null : i.default.getInstance().getEquipIconFrame("equip_" + e[t])),
                        (o.getChildByName("choose").active = !1);
                }
            }),
            __decorate([f(cc.Node)], t.prototype, "equip_item", void 0),
            __decorate([f(cc.Node)], t.prototype, "equip_view", void 0),
            __decorate([f(cc.Node)], t.prototype, "btn_view", void 0),
            __decorate([f(cc.Node)], t.prototype, "nom_equip_view", void 0),
            __decorate([f(cc.Label)], t.prototype, "equip_name_label", void 0),
            __decorate([f(cc.Sprite)], t.prototype, "equip_icon_sprite", void 0),
            __decorate([f(cc.Node)], t.prototype, "int_info_node", void 0),
            __decorate([f(cc.Node)], t.prototype, "equip_skill_list", void 0),
            __decorate([f(cc.Node)], t.prototype, "use_equip_view", void 0),
            __decorate([f(cc.Button)], t.prototype, "buy_btn", void 0),
            __decorate([f(cc.Button)], t.prototype, "sell_btn", void 0),
            __decorate([f(cc.Label)], t.prototype, "have_coin_num_label", void 0),
            __decorate([m], t)
        );
    })(r.default);
o.default = g;
